﻿using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;

using Tomahawk.Resources.Physics;

namespace Tomahawk.Runtime.Physics.Interfaces
{
    public sealed class Contact : ICloneable
    {
        public enum ContactType
        {
            Enter = 0,
            Stay = 1,
            Exit = 2
        }

        public ContactType type;
        public IPhysicsActor trigger;
        public IPhysicsActor actor;

        public object Clone()
        {
            return MemberwiseClone();
        }
    }

    public sealed class Collision : ICloneable
    {
        public IPhysicsActor actor0;
        public IPhysicsActor actor1;

        public object Clone()
        {
            return MemberwiseClone();
        }
    }

    public struct HitResult
    {
        public Vector3 position;
        public Vector3 normal;
        public IPhysicsActor actor;
        public string element;
    }

    [Flags]
    public enum HitFlags
    {
        None            = 0x00,
        StaticActors    = 0x02,
        InterpActors    = 0x04,
        DynamicActors   = 0x08,
        AllActors       = 0xFF,
    }

    public interface IPhysicsScene : IDisposable
    {
        #region Properties
        Vector3 GetGravity();
        void SetGravity(Vector3 gravity);
        #endregion

        #region Physics Simulation
        bool Simulate(float elapsedTime);
        bool WaitForResults(out List<Collision> collisions, out List<Contact> contacts);
        #endregion

        #region Actors
        bool CreateActor(string resource, out IPhysicsActor physActor);
        bool DestroyActor(IPhysicsActor physActor);
        #endregion

        #region Queries
        HitResult SingleLineCheck(Vector3 origin, Vector3 delta, HitFlags flags);
        #endregion
    }
}
